During World War I, a common method of fighting was trench warfare, when soldiers took shelter in long ditches as they fired at enemy troops.
In trench warfare, armed battles were fought from a network of trenches dug in the ground. Fairly well protected by these channels, which were often deep enough to stand in, soldiers fired at enemy troops who were ensconced in their own trenches. This type of combat declined after the First World War, when armored warfare (using heavy tanks and powerful artillery) became more common. Trench warfare then came to have the figurative meaning of "stalemate."